package com.saianfu.flowable.attendence

object ApplyConditionUtil {

    /**
     *根据用户等级、请假类型、请假天数来判断具体的审核层级，若审核层级返回为空时则需要拒绝该类型人员申请使用请假
     */
    fun getApproveLayerList(employeeLevel: EmployeeLevel, leaveType: LeaveType, dayCount: Float): Set<ApproveLevel> {
        val approveLayerList = mutableSetOf<ApproveLevel>()
        //分管领导无需请假审批
        if (employeeLevel.code == EmployeeLevel.ManagermentLayer.code) {
            return approveLayerList
        }
        //副主任及以上员工请假须先提交行政部人力资源科审核
        if (employeeLevel.code in arrayListOf(EmployeeLevel.DeputyDirector.code,
                        EmployeeLevel.Director.code, EmployeeLevel.ManagerAssistant.code,
                        EmployeeLevel.DeputyManager.code, EmployeeLevel.Manager.code)) {
            approveLayerList.add(ApproveLevel.HR)
        }
        //年休假、补休假、事假以外的其他假别请假须先提交行政部人力资源科审核。
        if (leaveType.code !in arrayListOf(LeaveType.AnnualLeave.code, LeaveType.ShiftLeave.code, LeaveType.PersonalLeave.code)) {
            approveLayerList.add(ApproveLevel.HR)
        }

        //年休假、补休假准假权限
        if (leaveType.code in arrayListOf(LeaveType.AnnualLeave.code, LeaveType.ShiftLeave.code)) {
            when (employeeLevel.code) {
                EmployeeLevel.Manager.code -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        // 部门负责人低于1天的年休假和补休假无审批层级，不允许请吗？经胡宇回复，要经过HR和分管领导审批
                        approveLayerList.add(ApproveLevel.HR)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }

                EmployeeLevel.DeputyManager.code, EmployeeLevel.ManagerAssistant.code -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }
                EmployeeLevel.Director.code, EmployeeLevel.DeputyDirector.code -> {
                    return if (dayCount >= 5) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }

                else -> {
                    return if (dayCount >= 2) {
                        approveLayerList.add(ApproveLevel.Office)
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Office)
                        approveLayerList
                    }
                }
            }
        }


        //事假、病假、丧假准假权限
        if (leaveType.code in arrayListOf(LeaveType.PersonalLeave.code, LeaveType.SickLeave.code, LeaveType.WelfareBereavementLeave.code)) {
            when (employeeLevel.code) {
                EmployeeLevel.Manager.code -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        // 部门负责人低于1天的事假、病假、丧假无审批层级，不允许请吗？经胡宇回复，要经过HR和分管领导审批
                        approveLayerList.add(ApproveLevel.HR)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }

                EmployeeLevel.DeputyManager.code, EmployeeLevel.ManagerAssistant.code -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }
                EmployeeLevel.Director.code, EmployeeLevel.DeputyDirector.code -> {
                    return if (dayCount >= 5) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList
                    }
                }

                else -> {
                    return if (dayCount >= 5) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList
                    }
                }
            }
        }
        //探亲假、产假、哺乳假、工伤假、计划生育假、婚假、护理假准假权限
        if (leaveType.code in arrayListOf(LeaveType.WelfareTanQinLeave.code,
                        LeaveType.WelfareMaternityLeave.code,
                        LeaveType.WelfareBuRuLeave.code,
                        LeaveType.WelfareAccidentialLeave.code,
                        LeaveType.WelfareJiHuaShengYuLeave.code,
                        LeaveType.WelfareMarriageLeave.code,
                        LeaveType.WelfareParentalLeave.code)) {
            when (employeeLevel.code) {
                EmployeeLevel.Manager.code -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        //福利假必须一次修完，不存在1天以下的情况
                        mutableSetOf()
                    }
                }
                else -> {
                    return if (dayCount >= 1) {
                        approveLayerList.add(ApproveLevel.Department)
                        approveLayerList.add(ApproveLevel.BranchLeader)
                        approveLayerList.add(ApproveLevel.ViceManager)
                        approveLayerList.add(ApproveLevel.GeneralManager)
                        approveLayerList
                    } else {
                        //福利假必须一次修完，不存在1天以下的情况
                        mutableSetOf()
                    }
                }
            }
        }
        return approveLayerList

    }


}